package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.api.RemotePointBalanceService;
import com.sikaryofficial.system.api.model.ScanRegisterVO;
import com.sikaryofficial.system.api.model.ScanTaskVO;
import com.sikaryofficial.system.api.model.UserPointResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 积分服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemotePointBalanceFallbackFactory implements FallbackFactory<RemotePointBalanceService> {
    private static final Logger log = LoggerFactory.getLogger(RemotePointBalanceFallbackFactory.class);

    @Override
    public RemotePointBalanceService create(Throwable throwable) {
        log.error("积分服务调用失败:{}", throwable.getMessage());
        return new RemotePointBalanceService() {
            /**
             * 扫码注册信息
             *
             * @param scanRegisterVO 用户信息
             * @param brand   品牌
             * @return 结果
             */
            @Override
            public R<Boolean> scanRegister(ScanRegisterVO scanRegisterVO, String brand) {
                return R.fail("根据类型查询字段数据失败:" + throwable.getMessage());
            }

            /**
             * 扫码任务信息
             *
             * @param scanTaskVO
             * @return
             */
            @Override
            public R<UserPointResultVO> scanTask(ScanTaskVO scanTaskVO) {
                return R.fail("扫码任务信息失败:" + throwable.getMessage());
            }

            /**
             * reset  Unused points email
             *
             * @return 结果
             */
            @Override
            public R<Boolean> autoSendResetEmailNotice() {
                return R.fail("reset  Unused points email fail:" + throwable.getMessage());
            }

            /**
             * Unused points
             *
             * @return 结果
             */
            @Override
            public R<Boolean> autoResetUnusedPoints() {
                return R.fail(" Unused points fail:" + throwable.getMessage());
            }
        };
    }
}
